﻿using System;
using System.Collections.Generic;
using Game.common;
using GameFramework.common;
using UnityEngine;

namespace Game.modules.map
{
    public class MapManager:Singleton<MapManager>
    {
        public int mapId;

        public MapConfig mapConfig;//地图相关的配置
        //已经放置player的MapCell
        private Dictionary<string, MapCell> _cells = new Dictionary<string, MapCell>();
        
        //所有的player(基地，手动放置的都视为player)
        private Dictionary<long, GameObj> players = new Dictionary<long, GameObj>();
        //所有怪物
        private Dictionary<long, GameObj> enimys = new Dictionary<long, GameObj>();

        public void enterMap(int guanQiaId)
        {
            //根据管卡id找到关卡的配置
            //判断有没有此管卡
            //地图内的信息清空
            _cells.Clear();
            players.Clear();
            enimys.Clear();
            //从配置中根据地图id获取地图配置并赋值
            
            //初始化建筑
            initJidi();

            
            //初始化卡池

            //初始化出怪逻辑

            //初始化资源增长逻辑
        }

        private void initJidi()
        {
            MapCell jidi = new MapCell();
        }

        public Vector3 getCenterPos(Vector3 pos)
        {
            Vector3 centerPos = Vector3.zero;
            float modX = pos.x % 1;
            if (Math.Abs(modX) > 0.5)
            {
                centerPos.x = (int)(pos.x / 1) + (pos.x>0?1:-1);
            }
            else
            {
                centerPos.x = (int)(pos.x / 1);
            }
            float modZ = pos.z % 1;
            if (Math.Abs(modZ) > 0.5)
            {
                centerPos.z = (int)(pos.z / 1) + (pos.z>0?1:-1);
            }
            else
            {
                centerPos.z = (int)(pos.z / 1);
            }

            return centerPos;
        }
    }
}